<?php
declare(strict_types=1);

namespace App\Repositories\RebateGift;


use App\Enums\RoomEnum;
use App\Exceptions\BasicException;
use App\Models\MainDB\AccountLog;
use App\Models\MainDB\RoomPit;
use App\Models\MainDB\User;
use App\Repositories\GiftRepository;
use App\Repositories\UserRepository;
use App\Repositories\UserRoomRepository;
use App\Services\Tools\PushChatService;
use App\Services\Tools\PushService;
use App\Services\Tools\RedisService;
use App\Traits\Singleton;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

class RebateGiveRepository
{
    use Singleton;

    // 限制暴击倍数. <0 不限制
    protected function restrictMultiple(int $input, $divideMembers): int
    {
        $defaultPoolType = RebateCoinDivideMemberRepository::getInstance()->getDefaultPoolType();
        $deductRate      = $divideMembers->where('type', '!=', $defaultPoolType)->sum('rate');
        $deductCoin      = intval($input * $deductRate / 100);
        $defaultPool     = $divideMembers->where('type', $defaultPoolType)->first();
        $defaultPoolCoin = $defaultPool->coin;
        if ($deductCoin > $defaultPoolCoin) { // 限制暴击倍数 110
            return 110;
        }
        return -1;
    }

    /**
     * @throws BasicException
     * @throws Exception
     */
    public function give(int $roomId, int $userId, int $targetId, int $giftId, int $hitCount)
    {
        $count = $hitCount;
        DB::beginTransaction();
        try {
            $room = (new UserRoomRepository())->find($roomId);
            if (!$room || $room->sys_type_id != 38) {
                throw new BasicException(-1, '当前房间无法赠送此礼物');
            }
            if ($room->holder != $targetId) {
                throw new BasicException(-1, '只能选择主播进行赠送');
            }
            $gift = (new GiftRepository())->find($giftId);
            if (!$gift || $gift->op_type != 12) {
                throw new BasicException(-1, '当前礼物不允许连点');
            }
            $user   = (new UserRepository())->rebateGiftUser($userId, true);
            $target = (new UserRepository())->rebateGiftUser($userId);
            if (!$gift) {
                throw new BasicException(-1, '礼物不存在');
            }
            if (!$room) {
                throw new BasicException(-1, '房间不存在');
            }
            if (!$target) {
                throw new BasicException(-1, '收礼用户不存在');
            }
            $input = $gift->price * $count;
            if ($user->money < $input) { // 金币不足
                throw new BasicException(42004);
            }
            $poolsSetting = RebatePoolSettingRepository::getInstance()->poolsSetting();
            $pools        = RebatePoolRepository::getInstance()->pools(true);
            // 分成
            $divideMembers     = RebateCoinDivideMemberRepository::getInstance()->get();
            $divideMembersCoin = Collection::make();
            foreach ($divideMembers as $member) {
                $memberType = $member->type;
                $divideMembersCoin->offsetSet($memberType, 0);
            }
            // 单次返现
            $accountLog = $poolsLog = $userRebateCoinMap = [];
            // while ($count) {
            //     $singleMembersGetCoin = $this->divideCoin($gift->price, $divideMembersCoin, $divideMembers, $pools, $poolsLog); // 奖池增加金额
            //     $userRebateCoinMap[] = $this->getRebateCoin($gift->price, $singleMembersGetCoin, $user, $pools, $poolsSetting, $poolsLog); // 金币奖励
            //     $count--;
            // }

            $isLucky        = (int)$this->checkIsLuck($count, $pools, $poolsSetting, $user);
            $membersGetCoin = $this->divideCoin($input, $divideMembersCoin, $divideMembers, $pools, $poolsLog); // 奖池增加金额


            $restrictMultiple         = $this->restrictMultiple($input, $divideMembers);
            $defaultPoolGetCoin       = $membersGetCoin[RebateCoinDivideMemberRepository::getInstance()->getDefaultPoolType()] ?? 0;
            $defaultPoolSingleGetCoin = intval($defaultPoolGetCoin / $count);
            while ($count) {
                $userRebateCoinMap[] = $this->getRebateCoin($gift->price, $defaultPoolSingleGetCoin, $user, $pools, $poolsSetting, $poolsLog, $isLucky, $restrictMultiple); // 金币奖励
                // $userRebateCoinMap[] = $this->getRebateCoin($gift->price, $singleMembersGetCoin, $user, $pools, $poolsSetting, $poolsLog, $isLucky); // 金币奖励
                $count--;
            }

            $userRebateCoin = (int)array_sum(array_column($userRebateCoinMap, 'coin'));                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            // 用户返利金币
            // 1.增加送礼记录
            $reward = RebateGiftRewardRepository::getInstance()->create([
                'room_id'        => $roomId,
                'user_id' => $userId,
                'target_user_id' => $targetId,
                'gift_id'        => $giftId,
                'count'          => $hitCount,
                'input'          => $input,
                'coin'           => $userRebateCoin,
            ]);
            // 2.用户扣费
            $decCoin        = $input - $userRebateCoin;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            // 用户投入金额 - 用户返现金币
            $decUserCoinRes = User::query()->where('user_id', $userId)->where('money', '>=',
                $decCoin)->decrement('money', $decCoin);
            $accountLog[]   = [
                'user_id'     => $userId,
                'user_money' => $input,
                'change_time' => Carbon::now()->timestamp,
                'change_desc' => "送出连击特殊礼物【{$gift->name}】",
                'change_type' => 229,
                'source_id'   => $reward->id,
                'room_id'     => $roomId,
                'popularity'  => $gift->cardiac,
            ];
            $accountLog[]   = [
                'user_id'     => $userId,
                'user_money' => $userRebateCoin,
                'change_time' => Carbon::now()->timestamp,
                'change_desc' => "获得连击特殊礼物【{$gift->name}】返利",
                'change_type' => 231,
                'source_id'   => $reward->id,
                'room_id'     => $roomId,
                'popularity'  => 0,
            ];
            if (!$decUserCoinRes) {
                throw new BasicException(-1, '金币不足');
            }
            // 3.增加用户收益
            $targetEarning = $divideMembersCoin->get(RebateCoinDivideMemberRepository::getInstance()->getUserType());
            if ($targetEarning > 0) {
                User::query()->where('user_id', $targetId)->increment('earnings', $targetEarning);
                $accountLog[] = [
                    'user_id'     => $targetId,
                    'user_money' => $targetEarning,
                    'change_time' => Carbon::now()->timestamp,
                    'change_desc' => "收到单人房礼物【{$gift->name}】",
                    'change_type' => 230,
                    'source_id'   => $reward->id,
                    'room_id'     => $roomId,
                    'popularity'  => $gift->cardiac,
                ];
            }
            // 4.增加送礼记录详情
            RebateGiftRewardDetailRepository::getInstance()->insertByRewardId($reward->id, $userRebateCoinMap);
            // 5.更新分成成员总金币
            $divideMembersCoinLog = [];
            foreach ($divideMembersCoin as $memberType => $memberCoin) {
                $member       = $divideMembers->where('type', $memberType)->first();
                $member->coin += $memberCoin;
                $member->save();
                $divideMembersCoinLog[] = [
                    'reward_id' => $reward->id,
                    'type'      => $memberType,
                    'input'     => $input,
                    'rate'      => $member->rate,
                    'amount'    => $memberCoin,
                    'balance'   => $member->coin,
                ];
            }
            // 6.记录分成成员金币增加日志
            RebateDivideCoinLogRepository::getInstance()->insert($divideMembersCoinLog);
            // 7.奖池更新
            $pools->each(function ($item) {
                $item->save();
            });
            // 8.奖池金币日志
            RebatePoolCoinLogRepository::getInstance()->insertByRewardId($reward->id, $poolsLog);
            // 9.用户投入产出
            RebateUserRepository::getInstance()->give($userId, $input, $userRebateCoin);
            // 10.资金明细
            AccountLog::query()->insert($accountLog);
            // 11.奖池开关更新
            $poolsSetting->each(function ($item) {
                $item->save();
            });
            // 12.增加房间人气
            $popularity = $gift->cardiac;
            if ($popularity > 0) {
                RedisService::addRoomPopularity($roomId, $popularity, 1, 10 * 60);
            }
            DB::commit();
        } catch (Exception $e) {
            DB::rollBack();
            throw new BasicException($e->getCode(), $e->getMessage());
        }


        // 推送
        $userRoomLabel   = RedisService::getUserChatLabel($userId, $roomId);
        $targetRoomLabel = RedisService::getUserChatLabel($targetId, $roomId);
        $this->pushGiftChatMessage($userRoomLabel, $targetRoomLabel, $hitCount, $gift, $room);
        $this->pushRebateMessage($userRoomLabel, $targetRoomLabel, $userRebateCoinMap, $gift, $room);

        return [
            'id'      => $reward->id,
            'room_id' => $roomId,
            'count'   => $hitCount,
            'user'    => $userRoomLabel,
            'target'  => $targetRoomLabel,
            'gift'    => [
                'id'      => $gift->id,
                'name' => $gift->name,
                'price' => $gift->price,
                'picture' => $gift->picture,
                'special' => $gift->special,
                'cardiac' => $gift->cardiac,
                'op_type' => $gift->op_type,
                'size'    => $gift->size
            ],
            'rebate'  => [
                'coin'        => array_sum(array_column($userRebateCoinMap, 'coin')),
                'is_multiple' => array_sum(array_column($userRebateCoinMap, 'multiple')) > 0 ? 1 : 0,
            ],
        ];
    }

    // 划分金币
    protected function divideCoin(int $input, $divideMembersCoin, $divideMembers, $pools, &$poolsLog): array
    {
        $platformType = RebateCoinDivideMemberRepository::getInstance()->getPlatformType();
        if ($divideMembers->sum('rate') > 100) { // 系统配置错误, 金额全部归公司
            $divideMembers->transform(function ($item) use ($platformType) {
                $item->rate = ($item->type == $platformType) ? 100 : 0;
                return $item;
            });
        }
        $useCoin = 0;
        $change  = [];
        foreach ($divideMembers->where('type', '!=', $platformType) as $value) { // 循环处理非公司部分的分成
            $type    = $value->type;
            $rate = $value->rate;
            $coin = ($rate <= 0) ? 0 : intval($input * $rate / 100);
            $pool = $pools->where('type',
                RebateCoinDivideMemberRepository::getInstance()->getPoolTypeByType($type))->first();
            $useCoin += $coin;
            if ($pool) {
                $pool->coin       += $coin;
                $pool->total_coin += $coin;
                $poolsLog[]       = [
                    'pool'    => $pool->type,
                    'source' => RebatePoolCoinLogRepository::getInstance()->getDivideType(),
                    'amount' => $coin,
                    'balance' => $pool->coin,
                ];
            }
            // echo "$type: " . $divideMembersCoin->$type . PHP_EOL;
            // $divideMembersCoin->$type += $coin;
            $memberCoin = $divideMembersCoin->get($type);
            $divideMembersCoin->offsetSet($type, $memberCoin + $coin);

            $change[$type] = $coin;
        }

        // $divideMembersCoin->$platformType += $input - $useCoin;
        $platformCoin    = $divideMembersCoin->get($platformType);
        $platformGetCoin = $input - $useCoin;
        $divideMembersCoin->offsetSet($platformType, $platformCoin + $platformGetCoin);
        $change[$platformType] = $platformGetCoin;
        return $change;
    }

    protected function checkIsLuck(int $count, $pools, $poolsSetting, $user): bool
    {
        $defaultType = RebatePoolRepository::getInstance()->getDefaultPoolType();
        $publicType  = RebatePoolRepository::getInstance()->getPublicPoolType();

        $defaultPool = $pools->where('type', $defaultType)->first();
        $publicPool  = $pools->where('type', $publicType)->first();

        $defaultSetting = $poolsSetting->where('id', $defaultPool->id)->first();
        $publicSetting  = $poolsSetting->where('id', $publicPool->id)->first();

        $isLucky = $this->checkPublicIsLucky($count, $publicPool, $publicSetting, $user);
        if ($isLucky) {
            return true;
        }
        return $this->checkDefaultIsLucky($count, $defaultPool, $defaultSetting);
    }

    protected function checkDefaultIsLucky(int $count, $pool, $setting): bool
    {
        if ($pool->multiple_interval <= 0) { // 大奖间隔
            $pool->multiple_interval = mt_rand($setting->multiple_min_interval, $setting->multiple_max_interval);
            // echo "[$pool->type][info]生成计数器间隔:" . $pool->multiple_interval . PHP_EOL;
        }
        if ($pool->multiple_interval > $pool->multiple_score + $count) { // 可以暴击
            return false;
        }
        return true;
    }

    protected function checkPublicIsLucky(int $count, $pool, $setting, $user): bool
    {
        if ($pool->multiple_interval <= 0) { // 大奖间隔
            $pool->multiple_interval = mt_rand($setting->multiple_min_interval, $setting->multiple_max_interval);
        }

        if ($pool->multiple_interval > $pool->multiple_score + $count) { // 不可以暴击
            return false;
        }

        if ($setting->is_open == 0 && $pool->coin > $setting->open_pool_coin) {
            $setting->is_open = 1;
        }

        if ($setting->is_open == 1 && $pool->coin < $setting->close_pool_coin) {
            $setting->is_open = 0;
        }

        if (($setting->is_open != 1 && $pool->coin < $setting->open_pool_coin) || ($setting->is_open == 1 && $pool->coin < $setting->close_pool_coin)) {
            return false;
        }

        // 验证补偿限制
        if ($setting->is_open_reparation == 1) {
            if ($user->rebate_gift->profit >= 0 || ($user->rebate_gift->input < $setting->reparation_user_min_input) || (abs($user->rebate_gift->profit) < $setting->reparation_user_min_loss)) {
                return false;
            }
        }
        return true;
    }

    // 获取分成金币
    protected function getRebateCoin(int $giftCoin, int $defaultPoolSingleGetCoin, $user, $pools, $poolsSetting, &$poolsLog, $isLucky, $restrictMultiple): array
    {
        $defaultType = RebatePoolRepository::getInstance()->getDefaultPoolType();
        $publicType  = RebatePoolRepository::getInstance()->getPublicPoolType();

        $defaultPool = $pools->where('type', $defaultType)->first();
        $publicPool  = $pools->where('type', $publicType)->first();

        $defaultSetting = $poolsSetting->where('id', $defaultPool->id)->first();
        $publicSetting  = $poolsSetting->where('id', $publicPool->id)->first();

        $pool = $this->getPublicPoolCoin($giftCoin, $user, $publicSetting, $publicPool, $poolsLog);
        if (!empty($pool)) {
            return $pool;
        }

        // 使用分成后的钱进行暴击
        return $this->getDefaultPoolCoin($giftCoin, $defaultPoolSingleGetCoin, $defaultSetting, $defaultPool, $poolsLog, $isLucky, $restrictMultiple);
    }

    protected function getPublicPoolCoin(int $initialCoin, $user, $setting, $pool, &$poolsLog): array
    {
        try {
            $pool->multiple_score += 1;                                          // 奖池计步器增加

            if ($pool->multiple_interval <= 0) { // 大奖间隔
                $pool->multiple_interval = mt_rand($setting->multiple_min_interval, $setting->multiple_max_interval);
                // echo "[$pool->type][info]生成计数器间隔:" . $pool->multiple_interval . PHP_EOL;
            }

            if ($initialCoin <= 0) {
                throw new BasicException(-1, '初始金币异常');
            }

            if ($setting->is_open == 0 && $pool->coin > $setting->open_pool_coin) {
                $setting->is_open = 1;
            }

            if ($setting->is_open == 1 && $pool->coin < $setting->close_pool_coin) {
                $setting->is_open = 0;
            }

            if ($pool->multiple_interval > $pool->multiple_score) {
                // echo "[$pool->type][Error]验证计数器不满足" . PHP_EOL;
                throw new BasicException(-1, '奖池计数器不满足');
            }

            if (($setting->is_open != 1 && $pool->coin < $setting->open_pool_coin) || ($setting->is_open == 1 && $pool->coin < $setting->close_pool_coin)) {
                throw new BasicException(-1, '当前奖池未开启');
            }


            // 验证补偿限制
            if ($setting->is_open_reparation == 1) {
                if ($user->rebate_gift->profit >= 0 || ($user->rebate_gift->input < $setting->reparation_user_min_input) || (abs($user->rebate_gift->profit) < $setting->reparation_user_min_loss)) {
                    // echo "[$pool->type][Error]验证暴击限制不满足" . PHP_EOL;
                    throw new BasicException(-1, '用户不满足暴击补偿条件');
                }
            }

            $pool->multiple_interval = mt_rand($setting->multiple_min_interval, $setting->multiple_max_interval);
            $pool->multiple_score    = 0;
            // echo "-----------------[success]-----------------" . PHP_EOL;
            // echo "[$pool->type]重制计步器，并生成计数器间隔:" . $pool->multiple_interval . PHP_EOL;
            $multiple   = mt_rand($setting->min_multiple, $setting->max_multiple); // 随机暴击倍数
            $rebateCoin = intval($initialCoin * $multiple / 100);                // 初始金币 * 倍数/ 100
            $rebateCoin = $rebateCoin > $pool->coin ? $pool->coin : $rebateCoin; // 保证暴击金额不大于奖池金额
            // echo "[$pool->type]初始金币: $initialCoin, 返利金额: $rebateCoin" . PHP_EOL;
            // echo "[$pool->type]生成随机暴击概率: $multiple%" . PHP_EOL;
            // echo "-----------------[success]-----------------" . PHP_EOL;
            $pool->coin -= $rebateCoin;

            $poolsLog[] = [
                'pool'    => $pool->type,
                'source' => RebatePoolCoinLogRepository::getInstance()->getRebateType(),
                'amount' => -$rebateCoin,
                'balance' => $pool->coin,
            ];
            return [
                'pool'         => $pool->type,
                'initial_coin' => $initialCoin,
                'random_coin'  => $initialCoin,
                'coin'         => $rebateCoin,
                'multiple'     => $multiple,
            ];
        } catch (Exception $exception) {
            // echo  $exception->getMessage() . PHP_EOL;
            return [];
        }
    }

    protected function getDefaultPoolCoin(int $giftCoin, int $initialCoin, $setting, $pool, &$poolsLog, $isLucky, $restrictMultiple): array
    {
        try {
            // echo "[$pool->type][info]当前计数器间隔:" . $pool->multiple_interval . PHP_EOL;
            $pool->multiple_score += 1; // 奖池计步器增加

            if ($pool->multiple_interval <= 0) { // 大奖间隔
                $pool->multiple_interval = mt_rand($setting->multiple_min_interval, $setting->multiple_max_interval);
                // echo "[$pool->type][info]生成计数器间隔:" . $pool->multiple_interval . PHP_EOL;
            }

            if ($initialCoin <= 0) {
                throw new BasicException('初始金币异常');
            }

            // echo "当前间隔: $pool->multiple_interval, 当前分数: $pool->multiple_score, ";
            if ($pool->multiple_interval <= $pool->multiple_score) { // 可以暴击
                $randomCoin = $giftCoin;                             // 暴击按照礼物单价暴击
                if ($restrictMultiple > 0) {
                    $multiple = $restrictMultiple;
                } else {
                    $multiple = mt_rand($setting->min_multiple, $setting->max_multiple);
                }

                $rebateCoin              = intval($randomCoin * $multiple / 100);
                $pool->multiple_interval = mt_rand($setting->multiple_min_interval, $setting->multiple_max_interval); // 重制间隔
                $pool->multiple_score    = 0;                                                                         // 清空分数
            } else { // 不可以暴击
                // $rebateCoin = $randomCoin;
                if ($isLucky == true) {
                    $randomCoin = $giftCoin;
                    $rebateCoin = $giftCoin;
                } else {
                    $randomCoin = intval($initialCoin * mt_rand($setting->rebate_coin_min_rate, $setting->rebate_coin_max_rate) / 100);
                    $rebateCoin = $randomCoin;
                }
                $multiple = 0;
            }

            if ($restrictMultiple < 0) {                                             // 不限制暴击: 不给给的比奖池还大
                $rebateCoin = $rebateCoin > $pool->coin ? $pool->coin : $rebateCoin; // 保证暴击金额不大于奖池金额
            }

            $pool->coin -= $rebateCoin;
            $poolsLog[] = [
                'pool'    => $pool->type,
                'source' => RebatePoolCoinLogRepository::getInstance()->getRebateType(),
                'amount' => -$rebateCoin,
                'balance' => $pool->coin,
            ];
            return [
                'pool'         => $pool->type,
                'initial_coin' => $initialCoin,
                'random_coin'  => $randomCoin,
                'coin'         => $rebateCoin,
                'multiple'     => $multiple
            ];
        } catch (Exception $e) {
            return ['pool' => $pool->type, 'initial_coin' => $initialCoin, 'coin' => 0, 'multiple' => 0];
        }
    }

    protected function pushRebateMessage($userRoomLabel, $targetRoomLabel, $userRebateCoinMap, $gift, $room)
    {
        $userId         = $userRoomLabel['user_id'];
        $roomId = $room->id;
        $pushObj = new PushService($userId, $roomId);
        $chatPushObj = new PushChatService($userId, $roomId);
        $targetNickname = $targetRoomLabel['nickname'];

        $multiple = array_sum(array_column($userRebateCoinMap, 'multiple'));
        $getCoin  = array_sum(array_column($userRebateCoinMap, 'coin'));
        if ($multiple > 0) {
            $chatPushObj->luckyRebateGift($userRoomLabel, $targetNickname, $getCoin, $gift);
            $pushObj->luckyRebateGift([$gift], $userRoomLabel, $targetRoomLabel, $getCoin);
        }
    }

    protected function pushGiftChatMessage($userRoomLabel, $targetRoomLabel, $count, $gift, $room): void
    {
        $pit                     = RoomPit::query()
            ->where('room_id', $room->id)
            ->where('user_id', $targetRoomLabel['user_id'])
            ->value('pit_number');
        $data = [
            'gift_id'       => $gift->id,
            'gift_pic' => $gift->picture,
            'gift_name' => $gift->name,
            'gift_price' => $gift->price,
            'gift_special' => $gift->special,
            'gift_num'     => $count,
            'room_sys_type' => $room->room_sys_type,
            'pits'          => $pit,
            'user_is_new'   => $userLabel->user_is_new ?? 0,
            'room_id'       => $room->id,
            'room_name'     => $room->room_name,
            'is_all'        => 0,
        ];
        $data = array_merge($data, $userRoomLabel);
        $data['user_in_room_id'] = $room->id; //  获取房间
        $data['room_type']       = RoomEnum::clientRoomType($room->sys_type_id);
        $data['is_exclusive']    = 0;

        $message = "<font color='#FFDFB4'>送给</font>";
        $message .= "<font color='#B08DFF'>{$targetRoomLabel['nickname']}</font>";
        $message .= "<font color='#2FE5FF'>{$gift->name}x$count</font>";

        (new PushChatService($userRoomLabel['user_id'], $room->id))->giveRebateGift($message, $data);
        if ($gift->price > 131400) {
            $airingMessage = "<font color='ECE9FF'>在</font>";
            $airingMessage .= "<font color='#FF8DF8'>{$room->room_name}</font>";
            $airingMessage .= "<font color='#ECE9FF'>房间送出</font>";
            $airingMessage .= "<font color='#2FE5FF'>{$gift->name} x $count</font>";
            (new PushChatService($userRoomLabel['user_id'], $room->id))->airingGiveGift($airingMessage, $data);
        }

        $cmdMessage = [
            'room_id'      => $room->id,
            'gift_list' => [
                [
                    'user_id'        => $targetRoomLabel['user_id'],
                    'user_id_from' => $userRoomLabel['user_id'],
                    'nickname_from' => $userRoomLabel['nickname'],
                    'head_picture'  => $userRoomLabel['head_picture'],
                    'nickname_to'   => $targetRoomLabel['nickname'],
                    'gift_id'       => $gift->id,
                    'gift_name'     => $gift->name,
                    'price'         => $gift->price,
                    'category_id'   => $gift->category_id,
                    'op_type'       => $gift->op_type,
                    'picture'       => $gift->picture,
                    'special'       => $gift->special,
                    'number'        => $count,
                    'pit_number'    => $pit ?: 0,
                    'is_chart_let'  => $gift->is_chart_let ?? 0,
                    'special_config' => $gift->special_config ?? [],
                    'target_special' => 'room', // 接受特效: 房间
                    'size'           => $gift->size,
                ]
            ],                                                       // 礼物列表
            'pit_list'  => [], // 返回空不处理
            'cardiac_list' => [], // 返回空不处理心动值列表
            'contribution' => RedisService::getRoomCharm($room->id), // 房间总心动值
            'show_cat'     => 0,
            'user_id'      => $userRoomLabel['user_id'],
            'type'         => PushService::PUSH_REBATE_GIFT_GIVE,
        ];
        (new PushService($userRoomLabel['user_id'], $room->id))->rebateGiftChatRoom($cmdMessage);
    }
}